package com.tudouji.project.mt.http.token;

import com.meituan.sdk.internal.exceptions.MtSdkException;
import com.meituan.sdk.internal.utils.SignerUtil;
import com.tudouji.common.utils.DateUtils;
import com.tudouji.framework.config.MTConfig;

import java.util.HashMap;
import java.util.Map;

public class AppAuthTokenUtils {

    //业务授权URL
    private static String AUTH_URL="https://open-erp.meituan.com/general/auth";

    //拼装授权URL
    public static String completeAUTHURL() throws MtSdkException {
        String developerId = MTConfig.getDeveloperId().toString();
        String businessId = "18";
        String timestamp = DateUtils.getDateTime().toString();
        String charset = "UTF-8";
//        String state = "tudouji";
//        String scope = "rms_base,rms_order,rms_member,rms_deposit,rms_scmultimate";
        Map<String,String> param = new HashMap();
        param.put("developerId",developerId);
        param.put("businessId",businessId);
        param.put("timestamp", timestamp);
        param.put("charset",charset);
//        param.put("state",state);
        //业务授权时传的scope，不传默认为：all
        //param.put("scope",scope);
        String sign = SignerUtil.getSign(MTConfig.getSignKey(), param);
        return AUTH_URL + "?developerId=" + developerId + "&timestamp=" + timestamp + "&charset="+ charset +
                "&businessId="+ businessId +"&sign="+ sign/* +"&state=" + state*/;
    }
}
